//
//  TMAPIParameter.m
//  复合发行4.0
//
//  Created by liubowen on 2017/8/30.
//  Copyright © 2017年 Beijing TMYK Technology co.,ltd. All rights reserved.
//

#import "TMAPIParameter.h"
#import "DictToString.h"
#import "TMUserManager.h"
#import "TMConst.h"
#import "UIDevice+FCUUID.h"
#import "TMAPIConfig.h"

@interface TMAPIParameter ()
@property (nonatomic, strong) NSMutableDictionary *parameterDictionary;
@end

@implementation TMAPIParameter

- (instancetype)init
{
    self = [super init];
    if (self) {
        _parameterDictionary = [NSMutableDictionary dictionary];
    }
    return self;
}
+ (TMAPIParameter *)defaultParameter
{
    static TMAPIParameter *parameter = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        parameter = [[self alloc] init];
    });
    return parameter;
}

- (NSDictionary *)parameterWithAPIPath:(NSString *)path param:(NSDictionary *)param
{
//    TMUserModel *userModel = [TMUserManager userModel];
//    if (![TMUserManager hasLogin]) {
//        userModel.user_id = @"0";
//    }
    // 每个接口都需要传app_key 和identity_key 默认带的
    NSString *appKey = KTMAPI_AppKey;
    NSString *identifyKey = KTMApI_IdentifyKey;
//    if (userModel.app_key && userModel.identify_key) {
//        appKey = userModel.app_key;
//        identifyKey = userModel.identify_key;
//    }
    
    NSMutableDictionary *defaultParameter = [@{@"platform":@(2),
                                               @"app_key":appKey,
                                               @"identify_key":identifyKey,
                                               @"user_id":@"",
                                               @"view_type":@(1),
                                               @"cover_format":@"m"
                                               } mutableCopy];

    // 把每个接口需要传入的具体参数添加到参数字典中去
    [defaultParameter addEntriesFromDictionary:param];
    
    [self.parameterDictionary setObject:path forKey:@"act"];
    [self.parameterDictionary setObject:[DictToString ConvertDictOrArrToString:defaultParameter]
                                 forKey:@"param"];
    
    return [_parameterDictionary copy];
}
+ (NSDictionary *)parameterWithAPIPath:(NSString *)path param:(NSDictionary *)param {
    TMAPIParameter *parameter = [TMAPIParameter defaultParameter];
    return [parameter parameterWithAPIPath:path param:param];
}

#pragma mark - app配置
- (NSDictionary *)appBaseConfigWithParam:(NSDictionary *)dic {
    return [self parameterWithAPIPath:TMAPI_BaseConfigPath
                                param:@{
                                        @"platform":@(2),
                                        @"imei":UUID
                                        }];
}

#pragma mark - 搜索

/**
 *  期刊资源搜索列表
 */
//- (NSDictionary *)magazineSearchContentlistWithkeyword:(NSString *)keyword
//                                              page_num:(NSInteger)page_num
//                                            page_limit:(NSInteger)page_limit {
//    return [self parameterWithAPIPath:TMAPI_magazinesearchList
//                                param:@{
//                                        @"keywords" : keyword,
//                                        @"page_num" : @(page_num),
//                                        @"page_limit" : @(page_limit),
//                                        @"from_type":@(3)
//                                        }];
//}
///**
// *  音频资源搜索列表
// */


@end



